home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / tbarco16 / barfrm16.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  9KB  |  295 lines

  1. unit Barfrm16;
  2. {Warning: If the TBarcode component is not installed,
  3.  You get an error message while loading this project!
  4.  If this happens to You, You must close he project
  5.  WITHOUT SAVING and read the documentation how
  6.  to install TBarcode as a VCL-component.
  7.  
  8.  Documentation is in the files ENGLISH.DOC and DEUTSCH.DOC.
  9.  
  10.  If You have any problems installing or using TBarcode,
  11.  please contact the author:
  12.  Juergen Schlottke
  13.  CIS-ID   100106,3034
  14.  Internet 100106.3034@compuserve.com
  15.  WWWeb    http://ourworld.compuserve.com/homepages/schlottke
  16.  
  17.  Consider that my mother language is German! So when
  18.  You ask me in English, please write slowly <bg>.
  19.  }
  20.  
  21. interface
  22.  
  23. uses
  24.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  25.   Forms, Dialogs, StdCtrls, Spin, ExtCtrls, Buttons, Bar16HL;
  26.  
  27. type
  28.   TDemoForm = class(TForm)
  29.     RGModulewidth: TRadioGroup;
  30.     RGCodetyp: TRadioGroup;
  31.     CB_ZoomSize: TCheckBox;
  32.     CB_HighDensity: TCheckBox;
  33.     CB_WidthReduce: TCheckBox;
  34.     Edit1: TEdit;
  35.     SE_HeightPerCent: TSpinEdit;
  36.     Label1: TLabel;
  37.     Label2: TLabel;
  38.     PrintBtn1: TBitBtn;
  39.     PrintBtn2: TBitBtn;
  40.     Barcode1: TBarcode;
  41.     ExitBtn: TButton;
  42.     procedure ExitBtnClick(Sender: TObject);
  43.     procedure PrintBtn1Click(Sender: TObject);
  44.     procedure PrintBtn2Click(Sender: TObject);
  45.     procedure FormCreate(Sender: TObject);
  46.     procedure Edit1Change(Sender: TObject);
  47.     procedure SE_HeightPerCentChange(Sender: TObject);
  48.     procedure RGCodetypClick(Sender: TObject);
  49.     procedure RGModulewidthClick(Sender: TObject);
  50.     procedure CB_HighDensityClick(Sender: TObject);
  51.     procedure CB_ZoomSizeClick(Sender: TObject);
  52.     procedure CB_WidthReduceClick(Sender: TObject);
  53.     procedure FormPaint(Sender: TObject);
  54.   private
  55.     { Private-Deklarationen }
  56.     procedure PrintDemo1;
  57.     procedure PrintDemo2;
  58.   public
  59.     { Public-Deklarationen }
  60.   end;
  61.  
  62. var
  63.   DemoForm: TDemoForm;
  64.  
  65. implementation
  66. uses Printers;
  67. {$R *.DFM}
  68.  
  69. procedure TDemoForm.ExitBtnClick(Sender: TObject);
  70. begin
  71.   Application.terminate;
  72. end;
  73.  
  74.  
  75.  
  76. procedure TDemoForm.PrintDemo2;
  77. {This print demo will create a barcode "on the fly" and
  78.  use it for printer output. No visual object needed.}
  79. var
  80.   x,y,lineheight:Integer;
  81.   xmm,ymm:Extended;
  82.   Point:TPoint;
  83.   MyBarcode:TBarcode;
  84. begin
  85.   MyBarcode:=TBarcode.create(self); {Create TBarcode object}
  86.   With MyBarcode do {Set some default options}
  87.   begin
  88.     {Take Caption from the barcode visible on the screen}
  89.     Bar_Caption:=Barcode1.Bar_caption;
  90.     {Set normal Height}
  91.     Bar_HeightPercent:=100;
  92.     {No high density codes}
  93.     Bar_HighDensity:=false;
  94.     {Normal width ist SC2}
  95.     Bar_Modulewidth:=SC2;
  96.     {With Laserprinters always use Widthreduce:=false!!!}
  97.     Bar_Widthreduce:=false;
  98.     {While printing always use Bar_ZoomSize:=false!!!}
  99.     Bar_ZoomSize:=false;
  100.   end;
  101.   printer.begindoc;
  102.   {Find out: How many device units are one mm}
  103.   xmm:=getdevicecaps(Printer.Handle,logpixelsX)/25.4;
  104.   ymm:=getdevicecaps(Printer.Handle,logpixelsY)/25.4;
  105.   {Find out printing offset on page}
  106.   escape(Printer.handle,Getprintingoffset,0,nil,@point);
  107.   {Adjust printing offset, so output starts at the
  108.    same coordinates on all printers}
  109.   SetViewPortOrgEx(Printer.handle,-point.x,-point.y,nil);
  110.   Printer.Canvas.Font.Name:='Arial';
  111.   Printer.Canvas.Font.Size:=12;
  112.   lineheight:=Printer.Canvas.textheight('Ay');
  113.   x:=round(25*xmm);
  114.   y:=round(25*ymm);
  115.   {EAN-8 demo}
  116.   Printer.Canvas.Textout(x,y,'EAN-8-Demo:');
  117.   inc(y,lineheight);
  118.   MyBarcode.Bar_Codetype:=EAN_8;
  119.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  120.   inc(y,Point.y+round(10*ymm));
  121.   {EAN-13 demo}
  122.   Printer.Canvas.Textout(x,y,'EAN-13-Demo:');
  123.   inc(y,lineheight);
  124.   MyBarcode.Bar_Codetype:=EAN_13;
  125.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  126.   inc(y,Point.y+round(10*ymm));
  127.   {UPC-A demo}
  128.   Printer.Canvas.Textout(x,y,'UPC-A-Demo:');
  129.   inc(y,lineheight);
  130.   MyBarcode.Bar_Codetype:=UPC_A;
  131.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  132.   inc(y,Point.y+round(10*ymm));
  133.   {UPC-E demo}
  134.   Printer.Canvas.Textout(x,y,'UPC-E-Demo:');
  135.   inc(y,lineheight);
  136.   MyBarcode.Bar_Codetype:=UPC_E;
  137.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  138.   inc(y,Point.y+round(10*ymm));
  139.   {CODE39 demo}
  140.   Printer.Canvas.Textout(x,y,'Code 39-Demo:');
  141.   inc(y,lineheight);
  142.   MyBarcode.Bar_Codetype:=CODE39;
  143.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  144.   inc(y,Point.y+round(10*ymm));
  145.   {Code 2/5 interleaved demo}
  146.   Printer.Canvas.Textout(x,y,'Code 2/5 interleaved-Demo:');
  147.   inc(y,lineheight);
  148.   MyBarcode.Bar_Codetype:=Code25i;
  149.   MyBarcode.Print(Printer.canvas,x,y,@Point);
  150.   inc(y,Point.y+round(10*ymm));
  151.   printer.enddoc;
  152.   MyBarcode.free;
  153. end;
  154.  
  155.  
  156. procedure TDemoForm.PrintDemo1;
  157. var
  158.   x,y,lineheight:Integer;
  159.   xmm,ymm:Extended;
  160.   Point:TPoint;
  161. begin
  162.   printer.begindoc;
  163.   {Find out: How many device units are one mm}
  164.   xmm:=getdevicecaps(Printer.Handle,logpixelsX)/25.4;
  165.   ymm:=getdevicecaps(Printer.Handle,logpixelsY)/25.4;
  166.   {Find out printing offset on page}
  167.   escape(Printer.handle,Getprintingoffset,0,nil,@point);
  168.   {Adjust printing offset, so output starts at the
  169.    same coordinates on all printers}
  170.   SetViewPortOrgEx(Printer.handle,-point.x,-point.y,nil);
  171.   {Now Print the Barcode at}
  172.   x:=round(50*Xmm);  {50mm from left}
  173.   y:=round(60*Ymm);  {60mm from top}
  174.   {Actual width and height of barcode are returned in "Point"}
  175.   Barcode1.Print(Printer.canvas,x,y,@Point);
  176.   x:=round(25*xmm);    {Set left:= 25mm}
  177.   inc(y,Point.y);      {increment with height of barcode}
  178.   inc(y,round(10*ymm));{increment 10mm}
  179.   with Printer.canvas.font do
  180.   begin
  181.     name:='Arial';
  182.     size:=12;
  183.   end;
  184.   {How many device units are one line printed with Arial-12}
  185.   lineheight:=Printer.canvas.textheight('X');
  186.   {Now print some lines of text}
  187.   Printer.canvas.textout(x,y,'Top left corner of barcode should be placed at:');
  188.   inc(y,lineheight);
  189.   Printer.canvas.textout(x,y,'50mm from left, 60mm from top of page');
  190.   inc(y,2*lineheight);
  191.   If Barcode1.Bar_Zoomsize then
  192.   begin
  193.     Printer.canvas.textout(x,y,'Warning: With "Bar_Zoomsize:=true" Your barcodes might be bad!');
  194.     inc(y,lineheight);
  195.     Printer.canvas.textout(x,y,'Please use "Bar_Zoomsize:=false" for printing best barcodes!');
  196.     inc(y,2*lineheight);
  197.   end;
  198.   If Barcode1.Bar_WidthReduce then
  199.   begin
  200.     Printer.canvas.textout(x,y,'"Warning: Bar_WidthReduce:=true"');
  201.     inc(y,lineheight);
  202.     Printer.canvas.textout(x,y,'This option should be used with dot-matrix and ink-jet printers only!');
  203.     inc(y,lineheight);
  204.     Printer.canvas.textout(x,y,'With laser printers You must use "Bar_WidthReduce:=false"!');
  205.     inc(y,2*lineheight);
  206.   end;
  207.   Printer.canvas.textout(x,y,'The dimensions of the printed barcode are:');
  208.   inc(y,lineheight);
  209.   Printer.canvas.textout(x,y,format('%d device units (%2.1fmm) in X-direction',[point.x,point.x/xmm]));
  210.   inc(y,lineheight);
  211.   Printer.canvas.textout(x,y,format('%d device units (%2.1fmm) in Y-direction',[point.y,point.y/ymm]));
  212.   printer.enddoc;
  213. end;
  214.  
  215.  
  216.  
  217.  
  218. procedure TDemoForm.PrintBtn1Click(Sender: TObject);
  219. begin
  220.   PrintDemo1;
  221. end;
  222.  
  223.  
  224. procedure TDemoForm.PrintBtn2Click(Sender: TObject);
  225. begin
  226.   PrintDemo2;
  227. end;
  228.  
  229. procedure TDemoForm.FormCreate(Sender: TObject);
  230. begin
  231.   SE_HeightPercent.value:=Barcode1.Bar_HeightperCent;
  232.   RGModuleWidth.itemindex:=ord(Barcode1.Bar_ModuleWidth);
  233.   RGCodetyp.itemindex:=ord(Barcode1.Bar_Codetype);
  234.   CB_HighDensity.checked:=Barcode1.Bar_HighDensity;
  235.   CB_ZoomSize.checked:=Barcode1.Bar_ZoomSize;
  236.   CB_WidthReduce.checked:=Barcode1.Bar_WidthReduce;
  237.   Edit1.text:=Barcode1.Bar_Caption;
  238. end;
  239.  
  240. procedure TDemoForm.Edit1Change(Sender: TObject);
  241. begin
  242.   Barcode1.Bar_Caption:=Edit1.text;
  243. end;
  244.  
  245. procedure TDemoForm.SE_HeightPerCentChange(Sender: TObject);
  246. begin
  247.   Barcode1.Bar_HeightPercent:=SE_HeightPercent.value;
  248. end;
  249.  
  250. procedure TDemoForm.RGCodetypClick(Sender: TObject);
  251. begin
  252.   Barcode1.Bar_CodeType:=btCodeTypes(RGCodetyp.itemindex);
  253. end;
  254.  
  255. procedure TDemoForm.RGModulewidthClick(Sender: TObject);
  256. begin
  257.   Barcode